package 栈.easy;


import java.util.Stack;

/**
 * 用栈实现队列
 * @author Lw中
 * @date 2020/10/23 9:34
 */
public class ErSanEr {

    // 输入栈 用于push
    public Stack<Integer> stack1 = new Stack<>();
    // 输出栈 用于pop、peak
    public Stack<Integer> stack2 = new Stack<>();

    /** Initialize your data structure here. */
    public ErSanEr() {

    }

    /** Push element x to the back of queue. */
    public void push(int x) {
       while (!stack2.isEmpty()) {
           stack1.push(stack2.pop());
       }
       stack1.push(x);
    }

    /** Removes the element from in front of queue and returns that element. */
    public int pop() {
        while (!stack1.isEmpty()) {
            stack2.push(stack1.pop());
        }
        Integer pop = stack2.pop();
        return pop;
    }

    /** Get the front element. */
    public int peek() {
        while (!stack1.isEmpty()) {
            stack2.push(stack1.pop());
        }
        Integer peek = stack2.peek();
        return peek;
    }

    /** Returns whether the queue is empty. */
    public boolean empty() {
        if (stack1.isEmpty() && stack2.isEmpty()) {
            return true;
        }
        return false;
    }

    public static void main(String[] args) {

    }

}
